package com.lvmama.pangolin.HBaseOper;

import com.lvmama.pangolin.common.DateUtil;
import com.lvmama.pangolin.common.RowkeyGenerator;
import com.lvmama.pangolin.entity.mt.*;
import com.lvmama.pangolin.hbaseutil.HBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Component
public class MTHBEntityOperation {
	/**  
	* @Title：HBEntityOperation.java
	* @Author:zhoutianqi
	* @Description:
	* @Date：2017年3月7日下午3:52:00  
	*/
	@Autowired
	private HBaseUtils hBaseUtil;
	public boolean saveMTTicketProduct(TicketPdetailMt item,String rowkey,String tableName,String family,TicketProductMt param){
		Map<String,String> map = new HashMap<String,String>();
		map.put("detailId", item.getDetailId());
		map.put("companyCode", item.getCompanyCode());
		map.put("platformCode", item.getPlatformCode());
		map.put("cityCode", item.getCityCode());
		map.put("sceneryName", item.getSceneryName());
		map.put("sceneryAddr", item.getSceneryAddr());
		map.put("productId", item.getProductId());
		map.put("detailUrl", item.getDetailUrl());
		map.put("lowestPrice", item.getLowestPrice());
		map.put("score", item.getScore());
		map.put("imageNum", item.getImageNum());
		map.put("introduction", item.getIntroduction());
		map.put("saleCount", item.getSaleCount());
		map.put("scoreTag", item.getScoreTag());
		map.put("starLevel", item.getStarLevel());
		map.put("createTime", DateUtil.yyyyMMdd_NOT_.format(item.getCreateTime()));
		map.put("updateTime", DateUtil.yyyyMMdd_NOT_.format(item.getUpdateTime()));
		map.put("taskId", item.getTaskId());
		map.put("taskDate", DateUtil.yyyyMMdd_NOT_.format(item.getTaskDate()));
		map.put("rsrvStr1", item.getRsrvStr1());
		map.put("rsrvStr2", item.getRsrvStr2());
		map.put("rsrvStr3", item.getRsrvStr3());
		map.put("snapshotAddr", item.getSnapshotAddr());
		map.put("commTypeNum", String.valueOf(param.getCommTypeNum()));
		map.put("commodityNum", String.valueOf(param.getCommodityNum()));
		map.put("commPreferentialNum", String.valueOf(param.getCommPreferentialNum()));
		map.put("commPackageNum", String.valueOf(param.getCommPackageNum()));
		return hBaseUtil.save(map, tableName, family, rowkey);
	}
	public boolean saveMTTicketProduct(TicketProductMt item,String tableName,String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("priceGrade", item.getPriceGrade());
		map.put("refundCondGrade", item.getRefundCondGrade());
		map.put("preferentialGrade", item.getPreferentialGrade());
		map.put("booktimeGrade", item.getBooktimeGrade());
		map.put("efficientGrade", item.getEfficientGrade());
		map.put("productGrade", item.getProductGrade());
		return hBaseUtil.save(map, tableName, family, item.getId());
	}
	
	public boolean saveMTTicketCommodity(TicketCommodityMt item,String tableName,String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("priceGrade", String.valueOf(item.getPriceGrade()));
		map.put("refundCondGrade", String.valueOf(item.getRefundCondGrade()));
		map.put("preferentialGrade", String.valueOf(item.getPreferentialGrade()));
		map.put("booktimeGrade", String.valueOf(item.getBooktimeGrade()));
		map.put("efficientGrade", String.valueOf(item.getEfficientGrade()));
		map.put("commodityGrade", item.getCommodityGrade());
		return hBaseUtil.save(map, tableName, family, item.getId());
	}
	public boolean saveMTTicketCommodity(TicketCdetailMt item,String rowkey,String tableName,String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("detailId", item.getDetailId());
		map.put("commodityType", item.getCommodityType());
		map.put("commodityId", item.getCommodityId());
		map.put("commodityName", item.getCommodityName());
		map.put("commodityUrl", item.getCommodityUrl());
		map.put("productId", item.getProductId());
		map.put("saleCond", item.getSaleCond());
		map.put("refundCond", item.getRefundCond());
		map.put("rackRate", item.getRackRate());
		map.put("salePrice", item.getSalePrice());
		map.put("priceListId", item.getPriceListId());
		map.put("createTime", DateUtil.yyyyMMdd_NOT_.format(item.getCreateTime()));
		map.put("updateTime", DateUtil.yyyyMMdd_NOT_.format(item.getUpdateTime()));
		map.put("taskId", item.getTaskId());
		map.put("taskDate", DateUtil.yyyyMMdd_NOT_.format(item.getTaskDate()));
		map.put("cityCode", item.getCityCode());
		map.put("efficientTime", item.getEfficientTime());
		return hBaseUtil.save(map, tableName, family, rowkey);
	}

	public boolean saveMTTicketCommodity(MTTicket_CommodityDetail item, String rowkey, String tableName, String family) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("detail_id", item.getDetail_id());
		map.put("commodity_type", item.getCommodity_type());
		map.put("commodity_id", item.getCommodity_id());
		map.put("commodity_name", item.getCommodity_name());
		map.put("commodity_url", item.getCommodity_url());
		map.put("product_id", item.getProduct_id());
		map.put("sale_cond", item.getSale_cond());
		map.put("refund_cond", item.getRefund_cond());
		map.put("rack_rate", item.getRack_rate());
		map.put("sale_price", item.getSale_price());
		map.put("price_list_id", item.getPrice_list_id());
		map.put("create_time", DateUtil.yyyyMMdd_NOT_.format(item.getCreate_time()));
		map.put("update_time", DateUtil.yyyyMMdd_NOT_.format(item.getUpdate_time()));
		map.put("task_id", item.getTask_id());
		map.put("task_date", DateUtil.yyyyMMdd_NOT_.format(item.getTask_date()));
		map.put("city_code", item.getCity_code());
		return hBaseUtil.save(map, tableName, family, rowkey);
	}
	public boolean saveMTTicketCommoPrice(String taskId,Date createTime,String price,String commodityID,String tableName,String family,String productId){
		String rowKey = RowkeyGenerator.generateCommodityRowkey(commodityID, createTime, productId);
		Map<String,String> map = new HashMap<String,String>();
		map.put("taskId", taskId);
		map.put("grabTime", DateUtil.yyyyMMdd_NOT_.format(createTime));
		map.put("saleDate", DateUtil.yyyyMMdd_NOT_.format(createTime));
		map.put("salePrice", price);
		hBaseUtil.save(map, tableName, family, rowKey);
		return true;
	}

	public boolean saveMTTicketCommodity(MTTicketCommodityItem item, String tableName, String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("priceGrade", String.valueOf(item.getPriceGrade()));
		map.put("refundCondGrade", String.valueOf(item.getRefundCondGrade()));
		map.put("preferentialGrade", String.valueOf(item.getPreferentialGrade()));
		map.put("booktimeGrade", String.valueOf(item.getBooktimeGrade()));
		map.put("efficientGrade", String.valueOf(item.getEfficientGrade()));
		map.put("commodityGrade", item.getCommodity_grade());
		return hBaseUtil.save(map, tableName, family, item.getId());
	}

	public boolean saveMTTicketProduct(MTTicketProductItem item, String tableName, String family){
		Map<String,String> map = new HashMap<String,String>();
		map.put("priceGrade", item.getPriceGrade());
		map.put("refundCondGrade", item.getRefundCondGrade());
		map.put("preferentialGrade", item.getPreferentialGrade());
		map.put("booktimeGrade", item.getBooktimeGrade());
		map.put("efficientGrade", item.getEfficientGrade());
		map.put("product_grade", item.getProduct_grade());
		return hBaseUtil.save(map, tableName, family, item.getId());
	}
}
